home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / MEMLib.lha / MEMLib / Developer / Include / memwatch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-30  |  4.4 KB  |  126 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           235 Trillingham Lane                                 *
  7. * ======             Cary, NC 27513                                       *
  8. *                    BBS:(919)-471-6436                                   *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11. #ifndef D_MEMWATCH_H
  12. #define D_MEMWATCH_H
  13.  
  14. #include <exec/types.h>
  15. #include <exec/memory.h>
  16.  
  17. /* The following files are included so you won't get an error if */
  18. /* you include them AFTER this file.                             */
  19. #include <stdlib.h>   /* Get prototype for malloc() */
  20. #include <dos/dos.h>      /* Get prototype for getcwd() and getenv() */
  21. #include <string.h>   /* Get prototype for strdup() */
  22.  
  23. /* Flags for MWInit */
  24. #define MWF_NOCHECK   0x00000000 /* (compatibility - do not use)         */
  25. #define MWF_NOLOG     0x00000002 /* No debug messages                    */
  26. #define MWF_CHECK     0x00000004 /* Check mem whenever mem rtns called   */
  27. #define MWF_NOFREE    0x00000008 /* Don't free nonfreed memory           */
  28. #define MWF_NOFTRASH  0x00000010 /* Don't trash memory upon free         */
  29. #define MWF_NOATRASH  0x00000020 /* Don't trash memory upon alloc        */
  30. #define MWF_NOFKEEP   0x00000040 /* Don't keep memory after free         */
  31. #define MWF_MALLOCWRN 0x00000080 /* Warn about malloc'd mem not freed    */
  32. #define MWF_SERIAL    0x00000100 /* Use serial port for output           */
  33.  
  34. #define MWF_ACTIVE   0x80000000 /* PRIVATE - MemWatch is active          */
  35. #define MWF_ERROR    0x40000000 /* PRIVATE - Error discovered, terminate */
  36.  
  37. /* PRIVATE. Flags for the INTERNAL argument to MWAllocMem.               */
  38. #define MWI_MALLOC   0x00000001  /* Memory allocated with malloc         */
  39. #define MWI_VEC      0x00000002  /* Memory allocated with AllocVec       */
  40. #define MWI_ANY      (MWI_MALLOC|MWI_VEC)
  41.  
  42. /* Flags to tell MWReport how much to report */
  43. #define MWR_NONE 0   /* Don't report anything; just return    */
  44. #define MWR_SUM  1   /* Report current and total usage        */
  45. #define MWR_FULL 2   /* Report on all outstanding allocations */
  46.  
  47. #ifdef MWDEBUG
  48.  
  49. #ifdef AllocMem
  50. #undef AllocMem
  51. #endif
  52. #ifdef FreeMem
  53. #undef FreeMem
  54. #endif
  55. #ifdef AllocVec
  56. #undef AllocVec
  57. #endif
  58. #ifdef FreeVec
  59. #undef FreeVec
  60. #endif
  61. #ifdef malloc
  62. #undef malloc
  63. #endif
  64. #ifdef halloc
  65. #undef halloc
  66. #endif
  67. #ifdef calloc
  68. #undef calloc
  69. #endif
  70. #ifdef realloc
  71. #undef realloc
  72. #endif
  73. #ifdef free
  74. #undef free
  75. #endif
  76. #ifdef strdup
  77. #undef strdup
  78. #endif
  79. #ifdef getcwd
  80. #undef getcwd
  81. #endif
  82. #ifdef getenv
  83. #undef getenv
  84. #endif
  85.  
  86.  
  87. #define AllocMem(size,flags) MWAllocMem((long)(size), flags, 0, __FILE__, __LINE__)
  88. #define FreeMem(mem,size)    MWFreeMem(mem, (long)(size), 0, __FILE__, __LINE__)
  89. #define AllocVec(size,flags) MWAllocMem((long)(size), flags, MWI_VEC, __FILE__, __LINE__)
  90. #define FreeVec(mem)         MWFreeMem(mem, -1, MWI_VEC, __FILE__, __LINE__)
  91. #define malloc(size)         MWAllocMem((long)(size), 0, MWI_MALLOC, __FILE__, __LINE__)
  92. #define halloc(size)         malloc(size)
  93. #define calloc(nelt,esize)   MWAllocMem((long)((nelt)*(esize)), MEMF_CLEAR, MWI_MALLOC, __FILE__, __LINE__)
  94. #define realloc(mem,size)    MWrealloc(mem,(long)(size),__FILE__,__LINE__)
  95. #define free(mem)            MWFreeMem(mem, -1, MWI_MALLOC, __FILE__, __LINE__)
  96.  
  97. #define strdup(str)          MWStrDup(str, __FILE__, __LINE__)
  98. #define getcwd(b,size)       MWGetCWD(b,size,__FILE__,__LINE__)
  99. #define getenv(name)         MWGetEnv(name, __FILE__, __LINE__)
  100.  
  101. void MWInit      (LONG, LONG, char *);
  102. void MWTerm      (void);
  103. void *MWAllocMem (long, long, long, char *, long);
  104. void MWFreeMem   (void *, long, long, char *, long);
  105. void MWCheck     (void);
  106. void MWReport    (char *, long);
  107. void MWLimit     (LONG, LONG);
  108. void *MWrealloc  (void *, long, char *, long);
  109.  
  110. char *MWStrDup   (const char *, char *, long);
  111. char *MWGetEnv   (const char *, char *, long);
  112. char *MWGetCWD   (char *, int, char *, long);
  113.  
  114. #else /* MWDEBUG */
  115.  
  116. /* No memory debugging - make everything go away */
  117.  
  118. #define MWInit(a,b,c)
  119. #define MWTerm()
  120. #define MWCheck()
  121. #define MWReport(a,b)
  122. #define MWLimit(a,b)
  123.  
  124. #endif /* MWDEBUG */
  125. #endif /* D_MEMWATCH_H */
  126.